package net.lwf.exception;

public class AppException extends RuntimeException {

	private static final long serialVersionUID = 1L;

	public AppException() {
	}
	
	public AppException(Throwable throwable) {
		super(throwable);
		this.uniqueID = ExceptionId.getExceptionID();
		isLogged = false;
	}

	public AppException(Exception exc) {
		this("", ExceptionId.getExceptionID(exc.getMessage()));
		causedByException = exc;
		isLogged = false;
	}

	public AppException(Exception exc, String msg) {
		this(msg, ExceptionId.getExceptionID(exc.getMessage()));
		causedByException = exc;
		isLogged = false;
	}

	public AppException(String msg) {
		this(msg, ExceptionId.getExceptionID());
		causedByException = null;
		isLogged = false;
	}

	public AppException(String msg, String uniqueID) {
		super(msg + System.getProperty("line.separator") + "uniqueLogId" + ":" + uniqueID);
		this.uniqueID = uniqueID;
	}

	public boolean isLogged() {
		return isLogged;
	}

	public void setLogged() {
		isLogged = true;
	}

	public String getUniqueID() {
		return uniqueID;
	}

	public Exception getCausedByException() {
		return causedByException;
	}

	public String getMessage() {
		String msg = super.getMessage();
		if (causedByException == null)
			return msg;
		if (msg == null)
			return "original net.lwf.exception is: " + causedByException.toString();
		else
			return msg + "; original net.lwf.exception is: "
					+ causedByException.toString();
	}

	protected boolean isLogged;
	protected String uniqueID;
	private Exception causedByException;

}
